import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';

import nodejs from '@dfeidao/atom-web/msg/nodejs';
import refresh from '@dfeidao/atom-web/url/refresh';
import { productid } from '../../atom/config';
import error from '@dfeidao/atom-web/msgbox/error';

export default async function a003(fd: IFeidaoAiBrowserComponent) {
	// todo
		// 题编号
		const question_no=get(fd,'arr');

		// 题目类型
		const topic_type="判断题";
		const re = await nodejs<{dt: Array<{topic: string,right_answer:string}>}>('question-bank/zj-000005/s003',{
			filter:{
				topic_type
			}
		});
		// 题目内容
		const topic1=fd.data.node.querySelector<HTMLInputElement>('[data-id="topic"]');
		const topic=topic1.value;
	
		// 正确内容
		const Y=fd.data.node.querySelectorAll<HTMLInputElement>('[data-id="Y"]:checked');
		const N=fd.data.node.querySelectorAll<HTMLInputElement>('[data-id="N"]:checked');

		let right_answer="";
		if (Y.length === 0 && N.length === 0) {
			error("请选择正确答案");

		} else if (Y.length > 0 && N.length === 0) {
			right_answer = "Y";
		} else if (Y.length === 0 && N.length > 0) {
			right_answer = "N";
		}

		const res = await nodejs<{code: 1|0;result: string}>('question-bank/zj-000006/s002',{
			filter:{
				productid,
				topic_type,
				topic,
				right_answer,
				question_no
			}

		});
		for (let i=0;i < re.dt.length;i++) {
			if (topic === re.dt[i].topic&&right_answer===re.dt[i].right_answer) {
				return;
			}
			}
		if (res.code === 1) {
			alert("修改成功");
			refresh();

			} else {
				alert("修改失败");
			}
}
